<?php
/**
 * iPAction inteface
 * Interface for action
 *
 * @author Patrice Ferlet <metal3d@copix.org> 
 * @package structs
 * @license http://opensource.org/licenses/lgpl-3.0.html GNU Lesser General Public License Version 3.0 (LGPLv3)
*/


interface iPAction {
    function beforeProcess();
    function afterProcess();
}


/* 
 * PAction
 * Action based class to call process made on actiongroups
 *
 * @author Patrice Ferlet <metal3d@copix.org> 
 */

class PActions implements iPAction{

    /**
    * Try to do something before action is proceed
    * @return PActionReturn or bool
    */
    function beforeProcess(){
        return true;
    }

    /**
    * Try to do something after action is proceed
    * @return PActionReturn or bool
    */
    function afterProcess(){
        return true;
    }

    /**
    * Process action, calls beforeProcess and afterProcess
    * If one of beforeProcess or afterProcess returns PActionReturn, then those returns are used
    */
    function process(){
        //first, we check "beforeProcess"
        $ret = $this->beforeProcess();
        if($ret instanceof PActionReturn){
            return $r;
        }

        //nothing to do with beforeProcess, we can now call action
        $call="process"._kernel()->getParam("action");
        $ra = $this->$call();
        
        //try to call afterProcess
        $ret = $this->afterProcess();
        if($ret instanceof PActionReturn){
            return $r;
        }

        //nothing to do with afterProcess, we can return action return
        return $ra;
    }

}


/* 
 * PAction class
 * Base class to implement action.
 *
 * @author Patrice Ferlet <metal3d@copix.org> 
 */


class PActionReturn {
    const DISPLAY=1;
    const REDIRECT=2;
    const NONE=3;

    public $code;
    public $datas;

    public function __construct($code, $datas){
        $this->code = $code;
        $this->datas = $datas;
    }
}
